package bilibili;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.Objects;

/**
 * @author ilongsay
 * @date: Create in 2020-04-11 18:48
 */
public class BilibiliSetTitle {

    public static void renameFile(String filePath,String replaceName) {
        System.out.println("========start transform=============");
        File file = new File(filePath);


        File[] listFiles = file.listFiles();
        for (File listFile : Objects.requireNonNull(listFiles)) {
            if (!listFile.isDirectory()) {
                continue;
            }
            File file1 = new File(listFile.getAbsolutePath());
            File[] listFiles1 = file1.listFiles();

            for (File file2 : Objects.requireNonNull(listFiles1)) {
                String fileName = file2.getName();
                if (!fileName.contains(".flv")) {
                   continue;
                }
                //String infoNamePath =listFile.getAbsolutePath()+"/"+ fileName.split("_")[0]+".info";
                String infoNamePath = listFile.getAbsolutePath() + "/" + "77774320" + ".info";
                String newFileName = ReadFileGetName.readFileContent(infoNamePath).replace(replaceName,"");
                File newFilePath = new File(listFile.getAbsolutePath() + "/" + newFileName + ".flv");
                try {
                    file2.renameTo(newFilePath);
                    break;
                } catch (Exception e) {
                    break;
                }
            }
        }
        System.out.println("========endTransform============");

    }

    public static void test(int i) {
        if (i == 3) {
            System.out.println("3333333333");
            return;
        }
        if (i == 4) {
            System.out.println("4444444444");
        }
        if (i == 5) {
            System.out.println("5555555555");
        }
        System.out.println("test222222222");
    }

    public static void main(String[] args) throws UnsupportedEncodingException {

        String replaceName = "-尚硅谷-高校大学生C语言课程";
        renameFile("E:\\study\\尚硅谷C语言",replaceName);

    }
}
